<?php

namespace App\Containers\AppSection\Accreditation\Actions;

use App\Containers\AppSection\Accreditation\Models\Accreditation;
use App\Containers\AppSection\Accreditation\Tasks\CheckAccreditationTask;
use App\Containers\AppSection\Accreditation\Tasks\FindAccreditationByIdTask;
use App\Containers\AppSection\Accreditation\Tasks\SendToAccreditationTask;
use App\Containers\AppSection\Accreditation\Tasks\UpdateAccreditationTask;
use App\Containers\AppSection\Accreditation\UI\API\Requests\SendToAccreditationRequest;
use App\Containers\AppSection\Log\Tasks\CreateLogTask;
use App\Containers\AppSection\Profile\Tasks\UpdateProfileTask;
use App\Ship\Parents\Actions\Action;

class SendToAccreditationSubAction extends Action
{
    public function run($profileId): Accreditation
    {
        app(CheckAccreditationTask::class)->run($profileId);

        $accreditation = app(SendToAccreditationTask::class)->run([
            'profile_id' => $profileId,
            'stage' => 'moderator'
        ]);

        app(UpdateProfileTask::class)->run($profileId, [
            'accreditation_id' => $accreditation->id,
            'accreditation_status_key' => 'accreditation_checking'
        ]);

        app(CreateLogTask::class)->run($profileId, 'Отправка профиля на аккредитацию','accreditation',  $accreditation->id);

        return $accreditation;
    }
}
